﻿@using Abp.Json
@using Partner.Surround.Templates.Dto
@model GetTemplateForEditOutput
@section styles{
    <style type="text/css">
        body {
            background-color: #fafafa !important;
        }
    </style>
}

<div class="layui-fluid">
    <form class="layui-form" lay-filter="layui-form-template" style="padding: 15px 0 0 0;">
        <input type="hidden" name="id" />
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button class="layui-btn layui-hide" lay-submit lay-filter="LAY-template-front-submit" id="LAY-template-front-submit">立即提交</button>
            </div>
        </div>
    </form>
</div>

@section scripts{
    <script type="text/javascript">
        layui.config({
            base: '/lib/layui-extend-modules/' //静态资源所在路径
        }).use(['jquery', 'form', 'layer', 'table'], function () {
            var $ = layui.$,
                form = layui.form;

            var index = parent.layer.getFrameIndex(window.name); //获取窗口索引
            parent.layer.iframeAuto(index);

            //初始化表单
            form.val("layui-form-template",@Html.Raw(JsonExtensions.ToJsonString(Model.Template,true,false)));
            form.render();

            //触发表单提交
            layui.submitForm = function(){
                $("#LAY-template-front-submit").click();
            }

            //表单提交
            form.on('submit(LAY-template-front-submit)', function (data) {
                var field = {
                    template: data.field,
                };

                var waitIndex = parent.layer.load(2);
                abp.ajax({
                    url: "@Url.Action("CreateOrUpdateTemplate", "Templates")",
                    data: JSON.stringify(field),
                    abpHandleError: false
                }).done(function (data) {
                    if (data.code == 200) {
                        data.index = index;
                        parent.layui.currWindow().layui.callback(data);
                    }
                }).fail(function (jqXHR) {
                    parent.layer.msg(jqXHR.message, { icon: 5 });
                }).always(function () {
                    parent.layer.close(waitIndex);
                });

                return false;
            });
        });
    </script>
}
